package com.xinggq.pay.service.dto;

import com.xinggq.pay.service.entity.YsePayConfigEntity;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import com.xinggq.common.utils.Validate;

/**
 * 银盛支付配置DTO
 * @author xinggq
 * @date 2024/01/20
 */
@Schema(description = "银盛支付配置")
public record YsePayConfigDTO(

    @Schema(description = "配置ID")
    Long id,

    @Schema(description = "方法")
    @NotBlank(message = "方法不能为空")
    String method,

    @Schema(description = "方法说明")
    @NotBlank(message = "方法说明不能为空")
    String methodExplain,

    @Schema(description = "服务商商户号")
    @NotBlank(message = "服务商商户号不能为空")
    String partnerId,

    @Schema(description = "收款商户号")
    @NotBlank(message = "收款商户号不能为空")
    String sellerId,

    @Schema(description = "业务代码")
    @NotBlank(message = "业务代码不能为空")
    String businessCode,

    @Schema(description = "异步通知地址")
    @NotBlank(message = "异步通知地址不能为空")
    String notifyUrl
) {

  /**
   * 从 Entity 转换为 DTO
   *
   * @param entity YsePayConfigEntity 对象
   * @return YsePayConfigDTO 对象
   */
  public static YsePayConfigDTO fromEntity(YsePayConfigEntity entity) {

    Validate.objectNotNull(entity, "YsePayConfigEntity实体类不能为空");
    return new YsePayConfigDTO(entity.getId(), entity.getMethod(), entity.getMethodExplain(),
        entity.getPartnerId(), entity.getSellerId(), entity.getBusinessCode(),
        entity.getNotifyUrl());
  }

}
